<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The IntlDateFormatter class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="intltimezone.usedaylighttime.html">« IntlTimeZone::useDaylightTime</a></li>
      <li style="float: right;"><a href="intldateformatter.create.html">IntlDateFormatter::create »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.intl.html">intl</a></li>
    <li>The IntlDateFormatter class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.intldateformatter" class="reference">
 <h1 class="title">The IntlDateFormatter class</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL intl &gt;= 1.0.0)</p>

  
  <div class="section" id="intldateformatter.intro">
   <h2 class="title">简介</h2>
   <p class="simpara">
    Date Formatter is a concrete class that enables locale-dependent formatting/parsing 
    of dates using pattern strings and/or canned patterns.
   </p>
 
   <p class="simpara">
    This class represents the ICU date formatting functionality. 
    It allows users to display dates in a localized format or to parse strings 
    into PHP date values using pattern strings and/or canned patterns.
   </p> 
  </div>
  

  <div class="section" id="intldateformatter.synopsis">
   <h2 class="title">Class synopsis</h2>

   
   <div class="classsynopsis">
    <div class="ooclass">
     
    </div>

    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">IntlDateFormatter</strong>
     </span>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.create.html" class="methodname">__construct</a></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$locale</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$dateType</code><span class="initializer"> = IntlDateFormatter::FULL</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$timeType</code><span class="initializer"> = IntlDateFormatter::FULL</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="class.intltimezone.html" class="type IntlTimeZone">IntlTimeZone</a></span>|<span class="type"><a href="class.datetimezone.html" class="type DateTimeZone">DateTimeZone</a></span>|<span class="type">string</span>|<span class="type">null</span></span> <code class="parameter">$timezone</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="class.intlcalendar.html" class="type IntlCalendar">IntlCalendar</a></span>|<span class="type">int</span>|<span class="type">null</span></span> <code class="parameter">$calendar</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$pattern</code><span class="initializer"> = <strong><code>null</code></strong></span></span><br>)</div>

    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="intldateformatter.create.html" class="methodname">create</a></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$locale</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$dateType</code><span class="initializer"> = IntlDateFormatter::FULL</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$timeType</code><span class="initializer"> = IntlDateFormatter::FULL</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="class.intltimezone.html" class="type IntlTimeZone">IntlTimeZone</a></span>|<span class="type"><a href="class.datetimezone.html" class="type DateTimeZone">DateTimeZone</a></span>|<span class="type">string</span>|<span class="type">null</span></span> <code class="parameter">$timezone</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="class.intlcalendar.html" class="type IntlCalendar">IntlCalendar</a></span>|<span class="type">int</span>|<span class="type">null</span></span> <code class="parameter">$calendar</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$pattern</code><span class="initializer"> = <strong><code>null</code></strong></span></span><br>): <span class="type"><span class="type">?</span><span class="type"><a href="class.intldateformatter.html" class="type IntlDateFormatter">IntlDateFormatter</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.format.html" class="methodname">format</a></span>(<span class="methodparam"><span class="type"><span class="type"><a href="class.intlcalendar.html" class="type IntlCalendar">IntlCalendar</a></span>|<span class="type"><a href="class.datetimeinterface.html" class="type DateTimeInterface">DateTimeInterface</a></span>|<span class="type">array</span>|<span class="type">string</span>|<span class="type">int</span>|<span class="type">float</span></span> <code class="parameter">$datetime</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="intldateformatter.formatobject.html" class="methodname">formatObject</a></span>(<span class="methodparam"><span class="type"><span class="type"><a href="class.intlcalendar.html" class="type IntlCalendar">IntlCalendar</a></span>|<span class="type"><a href="class.datetimeinterface.html" class="type DateTimeInterface">DateTimeInterface</a></span></span> <code class="parameter">$datetime</code></span>, <span class="methodparam"><span class="type"><span class="type">array</span>|<span class="type">int</span>|<span class="type">string</span>|<span class="type">null</span></span> <code class="parameter">$format</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$locale</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.getcalendar.html" class="methodname">getCalendar</a></span>(): <span class="type"><span class="type">int</span>|<span class="type"><span class="type false">false</span></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.getdatetype.html" class="methodname">getDateType</a></span>(): <span class="type"><span class="type">int</span>|<span class="type"><span class="type false">false</span></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.geterrorcode.html" class="methodname">getErrorCode</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.geterrormessage.html" class="methodname">getErrorMessage</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.getlocale.html" class="methodname">getLocale</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code><span class="initializer"> = <strong><code>ULOC_ACTUAL_LOCALE</code></strong></span></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.getpattern.html" class="methodname">getPattern</a></span>(): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.gettimetype.html" class="methodname">getTimeType</a></span>(): <span class="type"><span class="type">int</span>|<span class="type"><span class="type false">false</span></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.gettimezoneid.html" class="methodname">getTimeZoneId</a></span>(): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.getcalendarobject.html" class="methodname">getCalendarObject</a></span>(): <span class="type"><span class="type"><a href="class.intlcalendar.html" class="type IntlCalendar">IntlCalendar</a></span>|<span class="type"><span class="type false">false</span></span>|<span class="type">null</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.gettimezone.html" class="methodname">getTimeZone</a></span>(): <span class="type"><span class="type"><a href="class.intltimezone.html" class="type IntlTimeZone">IntlTimeZone</a></span>|<span class="type"><span class="type false">false</span></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.islenient.html" class="methodname">isLenient</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.localtime.html" class="methodname">localtime</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$offset</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><span class="type">array</span>|<span class="type"><span class="type false">false</span></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.parse.html" class="methodname">parse</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$offset</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><span class="type">int</span>|<span class="type">float</span>|<span class="type"><span class="type false">false</span></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.setcalendar.html" class="methodname">setCalendar</a></span>(<span class="methodparam"><span class="type"><span class="type"><a href="class.intlcalendar.html" class="type IntlCalendar">IntlCalendar</a></span>|<span class="type">int</span>|<span class="type">null</span></span> <code class="parameter">$calendar</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.setlenient.html" class="methodname">setLenient</a></span>(<span class="methodparam"><span class="type">bool</span> <code class="parameter">$lenient</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.setpattern.html" class="methodname">setPattern</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="intldateformatter.settimezone.html" class="methodname">setTimeZone</a></span>(<span class="methodparam"><span class="type"><span class="type"><a href="class.intltimezone.html" class="type IntlTimeZone">IntlTimeZone</a></span>|<span class="type"><a href="class.datetimezone.html" class="type DateTimeZone">DateTimeZone</a></span>|<span class="type">string</span>|<span class="type">null</span></span> <code class="parameter">$timezone</code></span>): <span class="type"><span class="type">?</span><span class="type">bool</span></span></div>

   }</div>
   

  </div>

  <div class="section" id="intldateformatter.seealso">
   <h2 class="title">参见</h2>
   <p class="para">
    <ul class="simplelist">
     <li class="member">
      <a href="http://www.icu-project.org/apiref/icu4c/udat_8h.html#details" class="link external">&raquo;&nbsp;ICU Date formatter</a>
     </li>
    </ul>
    <ul class="simplelist">
     <li class="member">
      <a href="https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax" class="link external">&raquo;&nbsp;ICU Date formats</a>
     </li>
    </ul>
   </p>
  </div>

  

<div class="section" id="intl.intldateformatter-constants">
 <h2 class="title">预定义常量</h2>

 <p class="para">
  These constants are used to specify different formats
  in the constructor for DateType and TimeType.
  <dl>
   
    <dt id="intldateformatter.constants.none">
     <strong><code>IntlDateFormatter::NONE</code></strong>
     (<span class="type">int</span>)
    </dt>

    <dd>

     <span class="simpara">Do not include this element</span>
    </dd>

   
   
    <dt id="intldateformatter.constants.full">
     <strong><code>IntlDateFormatter::FULL</code></strong>
     (<span class="type">int</span>)
    </dt>

    <dd>

     <span class="simpara">Completely specified style (Tuesday, April 12, 1952 AD or 3:30:42pm PST)</span>
    </dd>

   
   
    <dt id="intldateformatter.constants.long">
     <strong><code>IntlDateFormatter::LONG</code></strong>
     (<span class="type">int</span>)
    </dt>

    <dd>

     <span class="simpara">Long style (January 12, 1952 or 3:30:32pm)</span>
    </dd>

   
   
    <dt id="intldateformatter.constants.medium">
     <strong><code>IntlDateFormatter::MEDIUM</code></strong>
     (<span class="type">int</span>)
    </dt>

    <dd>

     <span class="simpara">Medium style (Jan 12, 1952)</span>
    </dd>

   
   
    <dt id="intldateformatter.constants.short">
     <strong><code>IntlDateFormatter::SHORT</code></strong>
     (<span class="type">int</span>)
    </dt>

    <dd>

     <span class="simpara">Most abbreviated style, only essential data (12/13/52 or 3:30pm)</span>
    </dd>

   
   
    <dt id="intldateformatter.constants.relative_full">
     <strong><code>IntlDateFormatter::RELATIVE_FULL</code></strong>
     (<span class="type">int</span>)
    </dt>

    <dd>

     <span class="simpara">
      The same as <strong><code>IntlDateFormatter::FULL</code></strong>, but yesterday, today, and tomorrow
      show as <code class="literal">yesterday</code>, <code class="literal">today</code>, and <code class="literal">tomorrow</code>,
      respectively.  Available as of PHP 8.0.0, for <code class="parameter">dateType</code> only.
     </span>
    </dd>

   
   
    <dt id="intldateformatter.constants.relative_long">
     <strong><code>IntlDateFormatter::RELATIVE_LONG</code></strong>
     (<span class="type">int</span>)
    </dt>

    <dd>

     <span class="simpara">
      The same as <strong><code>IntlDateFormatter::LONG</code></strong>, but yesterday, today, and tomorrow
      show as <code class="literal">yesterday</code>, <code class="literal">today</code>, and <code class="literal">tomorrow</code>,
      respectively.  Available as of PHP 8.0.0, for <code class="parameter">dateType</code> only.
     </span>
    </dd>

   
   
    <dt id="intldateformatter.constants.relative_medium">
     <strong><code>IntlDateFormatter::RELATIVE_MEDIUM</code></strong>
     (<span class="type">int</span>)
    </dt>

    <dd>

     <span class="simpara">
      The same as <strong><code>IntlDateFormatter::MEDIUM</code></strong>, but yesterday, today, and tomorrow
      show as <code class="literal">yesterday</code>, <code class="literal">today</code>, and <code class="literal">tomorrow</code>,
      respectively.  Available as of PHP 8.0.0, for <code class="parameter">dateType</code> only.
     </span>
    </dd>

   
   
    <dt id="intldateformatter.constants.relative_short">
     <strong><code>IntlDateFormatter::RELATIVE_SHORT</code></strong>
     (<span class="type">int</span>)
    </dt>

    <dd>

     <span class="simpara">
      The same as <strong><code>IntlDateFormatter::SHORT</code></strong>, but yesterday, today, and tomorrow
      show as <code class="literal">yesterday</code>, <code class="literal">today</code>, and <code class="literal">tomorrow</code>,
      respectively.  Available as of PHP 8.0.0, for <code class="parameter">dateType</code> only.
     </span>
    </dd>

   
  </dl>

 </p>

 <p class="para" id="intl.intldateformatter-constants.calendartypes">
  The following int constants are used to specify the calendar. 
  These calendars are all based directly on the Gregorian calendar.
  Non-Gregorian calendars need to be specified in locale. 
  Examples might include locale=&quot;hi@calendar=BUDDHIST&quot;.
  <dl>    
   
    <dt id="intldateformatter.constants.traditional">
     <strong><code>IntlDateFormatter::TRADITIONAL</code></strong>
     (<span class="type">int</span>)
    </dt>

    <dd>

     <span class="simpara">Non-Gregorian Calendar</span>
    </dd>

   
   
    <dt id="intldateformatter.constants.gregorian">
     <strong><code>IntlDateFormatter::GREGORIAN</code></strong>
     (<span class="type">int</span>)
    </dt>

    <dd>

     <span class="simpara">Gregorian Calendar</span>
    </dd>

   
  </dl>

 </p>
</div>

 
 

 </div>

 





































































































<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="intldateformatter.create.html">IntlDateFormatter::create</a> — Create a date formatter</li><li><a href="intldateformatter.format.html">IntlDateFormatter::format</a> — Format the date/time value as a string</li><li><a href="intldateformatter.formatobject.html">IntlDateFormatter::formatObject</a> — Formats an object</li><li><a href="intldateformatter.getcalendar.html">IntlDateFormatter::getCalendar</a> — Get the calendar type used for the IntlDateFormatter</li><li><a href="intldateformatter.getdatetype.html">IntlDateFormatter::getDateType</a> — Get the datetype used for the IntlDateFormatter</li><li><a href="intldateformatter.geterrorcode.html">IntlDateFormatter::getErrorCode</a> — Get the error code from last operation</li><li><a href="intldateformatter.geterrormessage.html">IntlDateFormatter::getErrorMessage</a> — Get the error text from the last operation</li><li><a href="intldateformatter.getlocale.html">IntlDateFormatter::getLocale</a> — Get the locale used by formatter</li><li><a href="intldateformatter.getpattern.html">IntlDateFormatter::getPattern</a> — Get the pattern used for the IntlDateFormatter</li><li><a href="intldateformatter.gettimetype.html">IntlDateFormatter::getTimeType</a> — Get the timetype used for the IntlDateFormatter</li><li><a href="intldateformatter.gettimezoneid.html">IntlDateFormatter::getTimeZoneId</a> — Get the timezone-id used for the IntlDateFormatter</li><li><a href="intldateformatter.getcalendarobject.html">IntlDateFormatter::getCalendarObject</a> — Get copy of formatterʼs calendar object</li><li><a href="intldateformatter.gettimezone.html">IntlDateFormatter::getTimeZone</a> — Get formatterʼs timezone</li><li><a href="intldateformatter.islenient.html">IntlDateFormatter::isLenient</a> — Get the lenient used for the IntlDateFormatter</li><li><a href="intldateformatter.localtime.html">IntlDateFormatter::localtime</a> — Parse string to a field-based time value</li><li><a href="intldateformatter.parse.html">IntlDateFormatter::parse</a> — Parse string to a timestamp value</li><li><a href="intldateformatter.setcalendar.html">IntlDateFormatter::setCalendar</a> — Sets the calendar type used by the formatter</li><li><a href="intldateformatter.setlenient.html">IntlDateFormatter::setLenient</a> — Set the leniency of the parser</li><li><a href="intldateformatter.setpattern.html">IntlDateFormatter::setPattern</a> — Set the pattern used for the IntlDateFormatter</li><li><a href="intldateformatter.settimezone.html">IntlDateFormatter::setTimeZone</a> — Sets formatterʼs timezone</li></ul>
</div>
</div></div></body></html>